// src/utils/notificationManager.js
import { createApp } from 'vue'
import GlobalNotification from '@/components/GlobalNotification.vue'

class NotificationManager {
  constructor() {
    this.notificationInstance = null
    this.init()
  }

  init() {
    // 检查是否已经存在通知容器
    let container = document.getElementById('global-notification-container')
    if (!container) {
      container = document.createElement('div')
      container.id = 'global-notification-container'
      document.body.appendChild(container)
    }

    // 创建通知实例
    const app = createApp(GlobalNotification)
    this.notificationInstance = app.mount(container)
  }

  success(message, duration = 3000) {
    this.notificationInstance.addNotification(message, 'success', duration)
  }

  error(message, duration = 3000) {
    this.notificationInstance.addNotification(message, 'error', duration)
  }

  warning(message, duration = 3000) {
    this.notificationInstance.addNotification(message, 'warning', duration)
  }

  info(message, duration = 3000) {
    this.notificationInstance.addNotification(message, 'info', duration)
  }
}

export default new NotificationManager()
